home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / iqb9109.zip / QUIKDEMO.BAS < prev    next >
BASIC Source File  |  1991-09-09  |  1KB  |  55 lines

  1. ' QuikDemo.Bas
  2. ' Program to demonstrate the QuickSort subprogram
  3. ' Portions Copyright by Microsoft Corporation
  4. '
  5. ' $INCLUDE: 'QSORT.BI'
  6.  
  7. DECLARE SUB Initialize ()
  8.  
  9. '  Create some random data
  10.  
  11. Initialize
  12.  
  13. '  Display the unsorted keys
  14.  
  15. FOR I% = 1 TO MaxIndex
  16.    PRINT SortArray(I%).SortKey,
  17. NEXT I%
  18. PRINT: PRINT
  19.  
  20. '  Sort the entire array
  21.  
  22. QuickSort 1, MaxIndex
  23.  
  24. '  Display the sorted keys
  25.  
  26. FOR I% = 1 TO MaxIndex
  27.    PRINT SortArray(I%).SortKey,
  28. NEXT I%
  29. PRINT
  30. END
  31.  
  32. '  Subprogram to initialize the sort array keys to random values
  33. '  This is a modified version of the Initialize routine from the
  34. '  SORTDEMO.BAS program supplied with QuickBASIC 4.5. Note that if
  35. '  you modify the SortType to be a non-string data type, you must
  36. '  change the lines below that construct a string version of the
  37. '  random key and the line which assigns the string version of the
  38. '  random key value to the sort key. However, for a real-world usage,
  39. '  of course, you won't need this Initialize subprogram.
  40.  
  41. SUB Initialize STATIC
  42.    RANDOMIZE TIMER            ' Seed the random-number generator.
  43.  
  44.    FOR I% = 1 TO MaxIndex
  45.       RandKey$ = ""
  46.       FOR J% = 1 TO 5
  47.          RandVal% = RandInt%(65, 90)
  48.          PRINT RandVal%
  49.          RandKey$ = RandKey$ + CHR$(RandVal%)
  50.       NEXT J%
  51.       LSET SortArray(I%).SortKey = RandKey$
  52.    NEXT I%
  53. END SUB
  54.  
  55.